package com.wsx.rpc.web.controller;

import com.wsx.rpc.api.ApiRequest;
import com.wsx.rpc.api.ApiResponse;
import com.wsx.rpc.web.oss.OssUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author wangshuaixin
 * @Title: com.wsx.rpc.web.controller.WebController
 * @Description: TODO
 * @date 2018/11/07
 */
@RestController
public class WebController {


    @RequestMapping(
            value = "/web/say",
            method = {RequestMethod.POST}
    )
    public ApiResponse say(@RequestBody ApiRequest apiRequest) {
        ApiResponse response = new ApiResponse();
        response.setCode(apiRequest.getCode() + 2);
        response.setMsg(apiRequest.getMsg() + 2);
        response.setDays(apiRequest.getDays());

        response.setList(apiRequest.getList());
        response.setMap(apiRequest.getMap());
        response.setMoney(apiRequest.getMoney() + 2);
        response.setName(apiRequest.getName() + 2);
        response.setStatus(apiRequest.getStatus() + 2);
        response.setTime(new Date());

        response.setTitle(apiRequest.getTitle() + 2);
        try {
            Thread.sleep(505);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }


    @RequestMapping(
            value = "/web/oss",
            method = {RequestMethod.GET}
    )
    public String oss() {
        String key = "tts/nlp-00c2c3d0f40c455e9dc9901b399f8a40-00242d57a949404d8ff733956dfbe558.mp3";
        byte[] datas = OssUtils.getObject(key);
        if (null != datas) {
            return "success";
        }
        return "error";
    }
}
